using System;
using System.Text;
using System.Windows.Media;

namespace Utility.Helper
{
	public class Random
	{
		public const string NUMBER_AND_CHAR = "1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,J,K,M,N,P,Q,R,S,T,U,W,X,Y,Z";

		public const string NUMBER = "0,1,2,3,4,5,6,7,8,9";

		public const string CHAR = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";

		public Random()
		{
		}

		public static bool NextBoolean()
		{
			Guid guid = Guid.NewGuid();
			bool flag = (new System.Random(guid.GetHashCode())).NextDouble() > 0.5;
			return flag;
		}

		public static Color NextColor(int start = 1, int end = 255)
		{
			NextNum(1, 255);
			Color color = Color.FromRgb((byte)NextNum(1, 255), (byte)NextNum(1, 255), (byte)NextNum(1, 255));
			return color;
		}

		public static DateTime NextDatetime()
		{
			DateTime dateTime = NextDatetime(new DateTime(1970, 1, 1), new DateTime(2099, 1, 1));
			return dateTime;
		}

		public static DateTime NextDatetime(DateTime min, DateTime max)
		{
			System.Random random = new System.Random(Guid.NewGuid().GetHashCode());
			long ticks = min.Ticks + (long)((double)(max.Ticks - min.Ticks) * random.NextDouble());
			return new DateTime(ticks);
		}

		public static T NextEnum<T>()
		where T : struct
		{
			Type type = typeof(T);
			if (!type.IsEnum)
			{
				throw new InvalidCastException("必须是枚举类型。");
			}
			Array values = Enum.GetValues(type);
			T value = (T)values.GetValue(NextNum(0, values.Length - 1));
			return value;
		}

		public static int NextNum(int min, int max)
		{
			System.Random random = new System.Random(Guid.NewGuid().GetHashCode());
			return random.Next(min, max + 1);
		}

		public static string NextString(int size, string source = "1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,J,K,M,N,P,Q,R,S,T,U,W,X,Y,Z")
		{
			string str;
			bool flag;
			if ((size <= 0 ? false : !string.IsNullOrEmpty(source)))
			{
				string[] strArrays = source.Split(new char[] { ',' });
				int length = (int)strArrays.Length;
				StringBuilder stringBuilder = new StringBuilder();
				for (int i = 0; i < size; i++)
				{
					string str1 = strArrays[NextNum(0, length - 1)];
					if (i != 0)
					{
						flag = true;
					}
					else
					{
						flag = (str1 == "0" ? false : !(str1 == "O"));
					}
					if (!flag)
					{
						str1 = NextString(1, source);
					}
					stringBuilder.Append(str1);
				}
				str = stringBuilder.ToString();
			}
			else
			{
				str = string.Empty;
			}
			return str;
		}
	}
}